package cn.school;

import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Scanner;

import cn.school.util.DBUtil;

public class AddStudent {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		String sql = "insert into s_student(sname,sex,gradeid,birthday)values(?,?,?,str_to_date(?,'%Y-%m-%d'))";

		try (Connection con = DBUtil.getConnection(); PreparedStatement pst = con.prepareStatement(sql);) {

			// assert (con != null);// 断言

			System.out.println("输入姓名");
			String name = in.next();
			System.out.println("输入性别");
			String sex = in.next();
			System.out.println("输入年级");
			long gradeid = in.nextLong();
			System.out.println("输入出生日期");
			String date = in.next();
			// SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");

			// java.util.Date d = df.parse(date);

			pst.setString(1, name);
			pst.setString(2, sex);
			pst.setLong(3, gradeid);
			pst.setString(4, date);
			// pst.setDate(4, new java.sql.Date(d.getTime()));

			int i = pst.executeUpdate();
			System.out.println("改动了" + i + "条");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
